<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="ts" uri="/tdqs-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
  
  
    <title>Femto ACS Demo</title>
<!-- DEMO styles - specific to this page -->

<script type="text/javascript" src="<s:url value='/js/pages/device/device.js'/>"></script>

</head>
  
  <body>
  <div class="searchbar" title="查询设备">
			<form  class="hForm" >
				<div class="rowElem">
					<label>状态:</label>
					<select id="status" name="filterMap['status'].filterValue" >
						<option value="" selected="selected">全部</option>
						<option value="0" >未知</option>
						<option value="1" >已开户</option>
						<option value="2" >已激活</option>
						<option value="3" >未激活</option>
					</select>
					<input type="hidden"  name="filterMap['status'].filterName" value="status" />
					<input type="hidden"  name="filterMap['status'].expType" value="eq" />
            		<input type="hidden"  name="filterMap['status'].formatter" value="IntegerFormatter"/>
				</div>
				<div class="rowElem">
					<label>设备标识:</label>
					<ts:filtertext  formatter="likeformatter" maxlength="1000"  name="devSn" exptype="like" cssClass="dialoginput" style="width:200px"/>
				</div>
				<div class="rowElem">
					<label>主叫号码:</label>
					<ts:filtertext  formatter="likeformatter" maxlength="1000"  name="mdn" exptype="like" cssClass="dialoginput" style="width:200px"/>
				</div>
				<div class="rowElem">
					<label>厂商名称:</label>
					<ts:filtertext  formatter="likeformatter" maxlength="1000"  name="devManufac" exptype="like" cssClass="dialoginput" style="width:200px"/>
				</div>
		<%--<div id="searchDiv" >
			<table>
				<tr>
					<td>
						<label>devMac：</label>
					</td>
					<td class="elementColor" width="110">
						<ts:filtertext  formatter="likeformatter" maxlength="1000"  name="devMac" exptype="like" cssClass="dialoginput" style="width:200px"/>
					</td>
				</tr>
				<tr>
					
					<td class="textColor" style="padding-left:5px;">
						<label>devMac：</label>
					</td>
					<td class="elementColor" width="110">
						<ts:filtertext  formatter="likeformatter" maxlength="1000"  name="devMac" exptype="like" cssClass="dialoginput" style="width:200px"/>
					</td>
				</tr>
					<tr>
				<td class="listviewTD" align="right">
					<font color="red">*</font>选择域：
				</td>
				<td class="listviewContent">
				<s:textfield readonly="true" id="company"  cssClass="textTest" ></s:textfield>
				<s:hidden id="companyId" name="policy.topoIds" ></s:hidden>
				</td>
			</tr>
			</table>
		</div>
	
	--%></form>
</div>


<div class="list">
	<table  id="list1"></table>
	<div id="pager1"></div>
</div>
 <div class="deviceDetail" title="添加设备">
	<div id="subDiv"></div>
 </div>

  </body>
</html>
<SCRIPT LANGUAGE="JavaScript">
var treeObject;
var selectNode;
$(document).ready(function(){
	
	var setting = {
		check: {
				enable: true
			},
					url : "<s:url value='/policy/tree'/>", //获取节点数据的URL地址
					asyncParam : ["id"],
					async: {
					enable: true,
					url:"<s:url value='/topo/tree'/>",
					autoParam:["id"]
					},
					data: {
						key: {
							children: "nodes",
							name: "name",
							checked: "checked"
						}
					},
					callback : {
						onClick : zTreeOnCheck,// 点击每个节点的事件:
							
						onAsyncSuccess : function(event, treeId, treeNode, msg) {
					
							treeObject = $.fn.zTree.getZTreeObj("featureTree");;
							if(!selectNode){
								return;
							}
							selectNode = treeObject.getNodeByParam("id",selectNode.id, null);
							var pNode = selectNode.getParentNode();
							treeObject.expandNode(pNode, true, false, true);
			
							
							if(treeNode!=null){
						  		if(treeNode.nodes.length==0)
						     		treeNode.isParent =false;
						   		else
						     		treeNode.isParent =true;
						 		treeObject.updateNode(treeNode, true);
						   }

						},onCheck:function(event, treeId, treeNode){
						 	var nodes=treeObject.getCheckedNodes(true);
						 	var names="";
						 	var ids="";
						 	$.each(nodes,function(i,node){
						 		if(node.checked){
						 			names=names+node.name+" "
						 			ids=ids+node.id
						 			if(i<nodes.length-1){
						 				ids=ids+","
						 			}
						 		}
						 	
						 	})
						 	$("#company").val(names);
						 	$("#companyId").val(ids);
						 }
						
					}
				};
				

			$.fn.zTree.init($("#featureTree"), setting);
				
				$("#add_button").bind('click',function(){
					selectNode = treeObject.getNodeByParam("id",selectNode.id, null);
					$('#detail_panel').load('<s:url value="/topo/edit"/>?topo.parent.id='+selectNode.id);
				})

				$("#delete_button").bind('click',function(){
					selectNode = treeObject.getNodeByParam("id",selectNode.id, null);
					$.adAjax({
							type : "get",
							url : '<s:url value="/topo/delete"/>',// 目标地址
							beforeSend : function() {
								
								
							},
							complete : function() {

							},
							error : function() {

							},
							success : function(){
								selectNode = treeObject.getNodeByParam("id",selectNode.id, null);
								var pNode = selectNode.getParentNode();
								treeObject.reAsyncChildNodes(pNode, "refresh");	
								
								treeObject.selectNode(pNode);
								treeObject.expandNode(pNode, true, false, true);
								$('#detail_panel').load('<s:url value="/topo/detail"/>?id=' + pNode.id);
								
								//TODO parent icon not be changed.
							}
					});
					
				})				
				   $(window).bind("resize",function(){

	               		var width= $('#layout').width()- $('#tree_panel').width()-7;

						
					
					});
});

function zTreeOnCheck(event, treeId, treeNode) {
	    if (treeNode) {
			var cityObj = $("#company");
			cityObj.val(treeNode.name);
			companyNode = treeNode.id;
		    //updateDepartmentMenu(treeNode.id);
		    $("#divAround_department").css("background-color","#FFFFFF");
			$("#department").css("background-color","#FFFFFF");	
			//hideMenu();
		}
	}

$("#company").inputStyle({
		operatorId:"companyMenuBtn",
		operatorType:"text",
		operatorText:"选择",
		controllerWidth:200,
		operatorFun:popcd,
		imgFun:clearCompany
	});

function popcd(){
	new DDWin({
		el:'topoDiv'
		,dep:'divAround_company'
		,clickBody:'save'
	})
}
function clearCompany(){
	$("#company").val('');
	//$("#departmentId").attr("value","");
	//zTreeCompany = $("#companyTree").zTree(settingCompany);
	//updateDepartmentMenu(null);
	$("#divAround_department").css("background-color","#EBEBE4");
	$("#department").css("background-color","#EBEBE4");
	$("#department").val('');
	$("#departmentId").val('');
}

function submitData(){
	if(!$("#form1").valid()){
				return;
	}
	$.ajax({
            url: '<s:url value="/policy/save"/>?tdqssid=<%=session.getId()%>',
            type: 'post',
            data: $('form').serialize(),
            dataType: 'json',
            timeout: 1000,
            error: function()
            {
            },
            success: function(result)
            {
               reload();
            }
            });
	}
function  queryDevice(){
	$("#list1").setGridParam({url:baserUrl+'device/list?'+$('form').serialize()});
    $("#list1").trigger("reloadGrid");
    return false;
}

</script>
